<recordTarget typeCode="RCT" contextControlCode="OP">
    <patientRole classCode="PAT">
        <#if templateData.templateId=='2.16.156.10011.2.1.1.2'>
            <!--出生医学证明编号-->
            <id root="2.16.156.10011.1.9" extension="${docData.patientRole.patient.chuShengYXZMBH}"/>
        <#else>
            <!--健康档案标识号-->
            <id root="2.16.156.10011.1.2" extension="${docData.patientRole.id}"/>
        </#if>
        <#if templateData.templateId=='2.16.156.10011.2.1.1.11'>
            <!--住院号标识-->
            <id root="2.16.156.10011.1.12" extension="${docData.patientRole.patient.zhuYuanHBS}"/>
        </#if>
        <#if templateData.templateId=='2.16.156.10011.2.1.1.18'>
            <!--会诊记录表编号-->
            <#if docData.patientRole.huiZhengJLBBH??>
                <id root="2.16.156.10011.1.16" extension="${docData.patientRole.huiZhengJLBBH}"/>
            </#if>
            <!--病案号标识-->
            <#if docData.patientRole.bingAnHBS??>
                <id root="2.16.156.10011.1.13" extension="${docData.patientRole.bingAnHBS}"/>
            </#if>
        </#if>
        <#if templateData.templateId=='2.16.156.10011.2.1.1.20'>
            <!--病案号标识-->
            <id root="2.16.156.10011.1.13" extension="${docData.patientRole.patient.bingAnHBS}"/>
        </#if>
        <!--会诊记录特殊判断-->
        <#if templateData.templateId=='2.16.156.10011.2.1.1.19'>
            <patient classCode="PSN" determinerCode="INSTANCE">
                <name>${docData.patientRole.patient.name}</name>
            </patient>
        <#else>
            <#if docData.patientRole.addr??>
                <addr use="H">
                    <#if docData.patientRole.addr.houseNumber??>
                        <houseNumber>${docData.patientRole.addr.houseNumber}</houseNumber>
                    </#if>
                    <#if docData.patientRole.addr.streetName??>
                        <streetName>${docData.patientRole.addr.streetName}</streetName>
                    </#if>
                    <#if docData.patientRole.addr.township??>
                        <township>${docData.patientRole.addr.township}</township>
                    </#if>
                    <#if docData.patientRole.addr.county??>
                        <county>${docData.patientRole.addr.county}</county>
                    </#if>
                    <#if docData.patientRole.addr.city??>
                        <city>${docData.patientRole.addr.city}</city>
                    </#if>
                    <#if docData.patientRole.addr.state??>
                        <state>${docData.patientRole.addr.state}</state>
                    </#if>
                    <#if docData.patientRole.addr.postalCode??>
                        <postalCode>${docData.patientRole.addr.postalCode}</postalCode>
                    </#if>
                </addr>
            </#if>
            <#if docData.patientRole.telecom??>
                <telecom value="${docData.patientRole.telecom}"/>
            </#if>
            <patient classCode="PSN" determinerCode="INSTANCE">
                <#if docData.patientRole.patient.id??>
                    <id root="2.16.156.10011.1.3" extension="${docData.patientRole.patient.id}"/>
                </#if>
                <name>${docData.patientRole.patient.name}</name>
                <#if docData.patientRole.patient.administrativeGender??>
                    <administrativeGenderCode code="${docData.patientRole.patient.administrativeGender.code}"
                                              codeSystem="2.16.156.10011.2.3.3.4"
                                              displayName="${docData.patientRole.patient.administrativeGender.displayName}"
                                              codeSystemName="生理性别代码表(GB/T 2261.1)"/>
                </#if>
                <#if docData.patientRole.patient.birthTime??>
                    <birthTime value="${docData.patientRole.patient.birthTime}"/>
                </#if>
                <!--监护人（姓名、电话、与本人的关系）-->
                <#if docData.patientRole.patient.guardian??>
                    <guardian>
                        <#if docData.patientRole.patient.guardian.code??>
                            <code code="${docData.patientRole.patient.guardian.code.code}"
                                  displayName="${docData.patientRole.patient.guardian.code.displayName}"
                                  codeSystem="2.16.156.10011.2.3.3.8" codeSystemName="家庭关系代码表(GB/T 4761)"/>
                        </#if>
                        <#if docData.patientRole.patient.guardian.addr??>
                            <addr use="H">
                                <#if docData.patientRole.patient.guardian.addr.houseNumber??>
                                    <houseNumber>${docData.patientRole.patient.guardian.addr.houseNumber}</houseNumber>
                                </#if>
                                <#if docData.patientRole.patient.guardian.addr.streetName??>
                                    <streetName>${docData.patientRole.patient.guardian.addr.streetName}</streetName>
                                </#if>
                                <#if docData.patientRole.patient.guardian.addr.township??>
                                    <township>${docData.patientRole.patient.guardian.addr.township}</township>
                                </#if>
                                <#if docData.patientRole.patient.guardian.addr.county??>
                                    <county>${docData.patientRole.patient.guardian.addr.county}</county>
                                </#if>
                                <#if docData.patientRole.patient.guardian.addr.city??>
                                    <city>${docData.patientRole.patient.guardian.addr.city}</city>
                                </#if>
                                <#if docData.patientRole.patient.guardian.addr.state??>
                                    <state>${docData.patientRole.patient.guardian.addr.state}</state>
                                </#if>
                                <#if docData.patientRole.patient.guardian.addr.postalCode??>
                                    <postalCode>${docData.patientRole.patient.guardian.addr.postalCode}</postalCode>
                                </#if>
                            </addr>
                        </#if>
                        <#if docData.patientRole.patient.guardian.telecom??>
                            <telecom value="${docData.patientRole.patient.guardian.telecom}"/>
                        </#if>
                        <guardianPerson>
                            <name>${docData.patientRole.patient.guardian.name}</name>
                        </guardianPerson>
                    </guardian>
                </#if>
                <#if docData.patientRole.patient.maritalStatus??>
                    <maritalStatusCode code="${docData.patientRole.patient.maritalStatus.code}"
                                       codeSystem="2.16.156.10011.2.3.3.5"
                                       displayName="${docData.patientRole.patient.maritalStatus.displayName}"
                                       codeSystemName="婚姻状况代码表(GB/T 2261.2)"/>
                </#if>
                <#if docData.patientRole.patient.ethnicGroup??>
                    <ethnicGroupCode code="${docData.patientRole.patient.ethnicGroup.code}"
                                     codeSystem="2.16.156.10011.2.3.3.3"
                                     displayName="${docData.patientRole.patient.ethnicGroup.displayName}"
                                     codeSystemName="民族类别代码表(GB 3304)"/>
                </#if>
                <#if docData.patientRole.patient.birthplace??>
                    <birthplace>
                        <place classCode="PLC" determinerCode="INSTANCE">
                            <addr>${docData.patientRole.patient.birthplace}</addr>
                        </place>
                    </birthplace>
                </#if>
                <#if docData.patientRole.patient.employerOrganization??>
                    <employerOrganization>
                        <name>${docData.patientRole.patient.employerOrganization}</name>
                        <#if docData.patientRole.patient.telecom??>
                            <telecom value="${docData.patientRole.patient.telecom}"></telecom>
                        </#if>
                        <#if docData.patientRole.patient.employerOrganizationAddr??>
                            <addr>
                                <#if docData.patientRole.patient.employerOrganizationAddr.houseNumber??>
                                    <houseNumber>${docData.patientRole.patient.employerOrganizationAddr.houseNumber}</houseNumber>
                                </#if>
                                <#if docData.patientRole.patient.employerOrganizationAddr.streetName??>
                                    <streetName>${docData.patientRole.patient.employerOrganizationAddr.streetName}</streetName>
                                </#if>
                                <#if docData.patientRole.patient.employerOrganizationAddr.township??>
                                    <township>${docData.patientRole.patient.employerOrganizationAddr.township}</township>
                                </#if>
                                <#if docData.patientRole.patient.employerOrganizationAddr.county??>
                                    <county>${docData.patientRole.patient.employerOrganizationAddr.county}</county>
                                </#if>
                                <#if docData.patientRole.patient.employerOrganizationAddr.city??>
                                    <city>${docData.patientRole.patient.employerOrganizationAddr.city}</city>
                                </#if>
                                <#if docData.patientRole.patient.employerOrganizationAddr.state??>
                                    <state>${docData.patientRole.patient.employerOrganizationAddr.state}</state>
                                </#if>
                                <#if docData.patientRole.patient.employerOrganizationAddr.postalCode??>
                                    <postalCode>${docData.patientRole.patient.employerOrganizationAddr.postalCode}</postalCode>
                                </#if>
                            </addr>
                        </#if>
                    </employerOrganization>
                </#if>
                <#if docData.patientRole.patient.houseType??>
                    <household>
                        <houseType value="${docData.patientRole.patient.houseType}" xsi:type="BL"/>
                    </household>
                </#if>
                <#if docData.patientRole.patient.educationLevel??>
                    <educationLevel>
                        <educationLevelCode code="${docData.patientRole.patient.educationLevel.code}"
                                            codeSystem="2.16.156.10011.2.3.3.6"
                                            displayName="${docData.patientRole.patient.educationLevel.displayName}"
                                            codeSystemName="学历代码表(GB/T 4658)"/>
                    </educationLevel>
                </#if>

                <!-- 户籍信息 -->
                <#if docData.patientRole.patient.householdAddr??>
                    <household>
                        <place>
                            <addr>
                                <#if docData.patientRole.patient.householdAddr.houseNumber??>
                                    <houseNumber>${docData.patientRole.patient.householdAddr.houseNumber}</houseNumber>
                                </#if>
                                <#if docData.patientRole.patient.householdAddr.houseNumber??>
                                    <streetName>${docData.patientRole.patient.householdAddr.streetName}</streetName>
                                </#if>
                                <#if docData.patientRole.patient.householdAddr.houseNumber??>
                                    <township>${docData.patientRole.patient.householdAddr.township}</township>
                                </#if>
                                <#if docData.patientRole.patient.householdAddr.houseNumber??>
                                    <county>${docData.patientRole.patient.householdAddr.county}</county>
                                </#if>
                                <#if docData.patientRole.patient.householdAddr.houseNumber??>
                                    <city>${docData.patientRole.patient.householdAddr.city}</city>
                                </#if>
                                <#if docData.patientRole.patient.householdAddr.houseNumber??>
                                    <state>${docData.patientRole.patient.householdAddr.state}</state>
                                </#if>
                            </addr>
                        </place>
                    </household>
                </#if>
<#--                个人基本健康档案-->
                <#if templateData.templateId=='2.16.156.10011.2.1.1.1'>
                    <#if docData.patientRole.patient.occupation??>
                        <occupation>
                            <occupationCode code="${docData.patientRole.patient.occupation.code}"
                                            codeSystem="2.16.156.10011.2.3.3.7"
                                            displayName="${docData.patientRole.patient.occupation.displayName}"
                                            codeSystemName="职业类别代码表(GB/T 6565)" codeSystemVersion="职业类别代码表（GB/T 6565）"/>
                        </occupation>
                    </#if>
                </#if>
<#--                传染病-->
                <#if templateData.templateId=='2.16.156.10011.2.1.1.10'>
                    <#if docData.patientRole.patient.occupation??>
                    <occupation>
                        <occupationCode code="${docData.patientRole.patient.occupation.code}"
                                        codeSystem="2.16.156.10011.2.3.1.6"
                                        displayName="${docData.patientRole.patient.occupation.displayName}"
                                        codeSystemName="传染病患者职业代码表" codeSystemVersion="职业类别代码表（GB/T 6565）"/>
                    </occupation>
                    </#if>
                </#if>
            </patient>
        </#if>
    </patientRole>
</recordTarget>
